package com.harboursoftware.xstorage.operations;

import java.util.Map;

import com.google.common.collect.ListMultimap;
import com.harboursoftware.xstorage.XStorageException;
import com.harboursoftware.xstorage.ac.Permission;
import com.harboursoftware.xstorage.fs.XFileSystem;
import com.harboursoftware.xstorage.model.XElement;
import com.harboursoftware.xstorage.model.XUser;
import com.harboursoftware.xstorage.results.Result;

//提示：使用IOUtils.toInputStream(java.lang.String input)
//TODO : 把该类变成接口
/**
 * 抽象类，opration类的基类。
 * <p><b>Notes：</b>所有Operation的子类必须有一个无参数的构造器。</p>
 */
public abstract class Operation {
    protected XFileSystem fileSystem;

    /**
     * execute operation.
     * 
     * @param requester
     *            the requester
     * @param element
     *            the target element
     * @param headers
     *            http headers
     * @param parameters
     *            http request parameters
     * @return the result of operation
     */
    public abstract Result execute(XUser requester, XElement element, ListMultimap<String, String> headers,
        Map<String, String> parameters) throws XStorageException;

    /**
     * 获取执行该Operation所需的权限.
     * 
     * @return
     */
    public abstract Permission getRequiredPermission();

    public XFileSystem getFileSystem() {
        return fileSystem;
    }

    public void setFileSystem(XFileSystem fileSystem) {
        this.fileSystem = fileSystem;
    }
}
